/*两个有序连别的合并

#include <stdio.h>
#include <stdlib.h>

typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
    ElementType Data;
    PtrToNode   Next;
};
typedef PtrToNode List;

List Read(); //细节在此不表 
void Print( List L ); //细节在此不表；空链表将输出NULL 

List Merge( List L1, List L2 );

int main()
{
    List L1, L2, L;
    L1 = Read();
    L2 = Read();
    L = Merge(L1, L2);
    Print(L);
    Print(L1);
    Print(L2);
    return 0;
}

// 你的代码将被嵌在这里 
*/

void attach(List *pL, List* prear) {
    (*prear)->Next = *pL;
    *prear = (*prear)->Next;
    *pL = (*pL)->Next;
}
List Merge( List L1, List L2 ) {
    List front, rear, pa, pb;
    rear  = (List)malloc(sizeof(struct Node));
    front = rear;

    pa = L1->Next;
    pb = L2->Next;
    while (pa&&pb) {
        if (pa->Data <= pb->Data) {
            attach(&pa, &rear);
        } else {
            attach(&pb, &rear);
        }
    }
    rear->Next = pa ? pa : pb;
    L1->Next = NULL;
    L2->Next = NULL;
    return front;
}